//
//  ZJLivingDetailSelfTableViewCell.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/19.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJLivingDetailSelfTableViewCell.h"

@interface ZJLivingDetailSelfTableViewCell ()
/** 头像 */
@property (nonatomic, strong) UIImageView *headerImageView;
/** name */
@property (nonatomic, strong) UILabel *name;
/** 小箭头 */
@property (nonatomic, strong) UIImageView *arrows;
/** 聊天的背景 */
@property (nonatomic, strong) UIImageView *bgImageView;
/** 聊天内容 */
@property (nonatomic, strong) UILabel *contentLabel;
@end

@implementation ZJLivingDetailSelfTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor themeGrayColor];
        [self.contentView addSubview:self.headerImageView];
        [self.contentView addSubview:self.name];
        [self.contentView addSubview:self.arrows];
        [self.contentView addSubview:self.bgImageView];
        [self.bgImageView addSubview:self.contentLabel];
        
    }
    return self;
}

#pragma mark - Setter
- (void)setModel:(DRRRMessageContent *)model{
    _model = model;
    self.headerImageView.sd_layout
    .topSpaceToView(self.contentView, 5 * [UIScreen zj_screenHScale])
    .rightSpaceToView(self.contentView, 10 * [UIScreen zj_screenWScale])
    .widthIs(38 * [UIScreen zj_screenWScale])
    .heightEqualToWidth();
  
    
    self.name.sd_layout
    .topEqualToView(self.headerImageView)
    .rightSpaceToView(self.headerImageView, 10 * [UIScreen zj_screenWScale])
    .leftSpaceToView(self.contentView, 10 * [UIScreen zj_screenWScale])
    .heightIs([NSString heightWithTextFont:[UIFont titleTextFont]]);

    
    self.bgImageView.sd_layout
    .topSpaceToView(self.name, 3 * [UIScreen zj_screenHScale])
    .rightEqualToView(self.name)
    .widthIs(model.cell_bgImageView_width)
    .bottomSpaceToView(self.contentView, 5 * [UIScreen zj_screenHScale]);
  
    
    self.arrows.sd_layout
    .topSpaceToView(self.name ,6 * [UIScreen zj_screenHScale])
    .rightSpaceToView(self.headerImageView, 0)
    .leftSpaceToView(self.bgImageView, 0)
    .heightEqualToWidth();
    
     CGFloat labelWith = [UIScreen zj_screenWith] - self.headerImageView.width - (30 + 10 + 10 + 10) * [UIScreen zj_screenWScale];
    
    self.contentLabel.text = model.body;
    self.contentLabel.sd_layout
    .topSpaceToView(self.bgImageView, 10 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self.bgImageView, 15 * [UIScreen zj_screenWScale])
    .widthIs(model.cell_bgImageView_width - 30 * [UIScreen zj_screenWScale])
    .heightIs([self.contentLabel getLableSizeWithMaxWidth:labelWith].height);
    
    self.name.text = model.name;
    [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,ZJUSERINFORMODEL.ORG_ACCOUNT.PHOTO_URL]] placeholderImage:PlaceholderHeaderImage];
    
}

#pragma mark - Getters
- (UILabel *)name{
    if (_name == nil){
        _name = [UILabel new];
        _name.textColor = [UIColor textBlackColor];
        _name.font = [UIFont titleTextFont];
        _name.textAlignment = NSTextAlignmentRight;

    }
    return _name;
}

- (UIImageView *)headerImageView{
    if (_headerImageView == nil){
        _headerImageView = [UIImageView new];
        _headerImageView.sd_cornerRadius = @(19 * [UIScreen zj_screenWScale]);
    }
    return _headerImageView;
}

- (UIImageView *)arrows{
    if (_arrows == nil){
        _arrows = [UIImageView new];
    
        _arrows.image = [UIImage imageNamed:@"sanjiao_r"];
        _arrows.contentMode = UIViewContentModeLeft;
    }
    return _arrows;
}
- (UIImageView *)bgImageView{
    if (_bgImageView == nil){
        _bgImageView = [UIImageView new];
        _bgImageView.backgroundColor = [UIColor zj_colorWithHexString:@"9be85a"];
        _bgImageView.layer.cornerRadius = 3 * [UIScreen zj_screenWScale];
    }
    return _bgImageView;
}

- (UILabel *)contentLabel{
    if (_contentLabel == nil){
        _contentLabel = [UILabel new];
        _contentLabel.font = [UIFont titleTextFont];
        _contentLabel.textColor = [UIColor textBlackColor];
        _contentLabel.numberOfLines = 0;
        _contentLabel.lineSpace = 4 * [UIScreen zj_screenHScale];
        _contentLabel.characterSpace = 1;
        
    }
    return _contentLabel;
}
@end
